Class Creature

java.lang.Object
  extended by greenfoot.Actor
      extended by Creature

public abstract class Creature
extends greenfoot.Actor

A Creature is the base class for all alien beings in this scenario. It provides the basic abilities of creatures in this world.

Version:
1.0
Author:
Michael Kolling

Constructor Summary
Creature()
           
 
Method Summary
 boolean atWater()
          Return true if we have just seen water in front of us.
 boolean atWorldEdge()
          Test if we are close to one of the edges of the world.
 boolean carryingTomato()
          Check whether we are carrying a tomato.
abstract  java.lang.String getCurrentImage()
          This method must be defined in subclasses.
 void loadTomato()
          Load a tomato onto *another* creature.
 void move()
          Move forward roughly in the current direction.
protected  boolean randomChance(int percent)
          Return 'true' in exactly 'percent' number of calls.
 boolean removeTomato()
          Remove the tomato currently carried (and return true).
 void turn(int angle)
          Turn 'angle' degrees towards the right (clockwise).
 
Methods inherited from class greenfoot.Actor
act, addedToWorld, getImage, getIntersectingObjects, getNeighbours, getObjectsAtOffset, getObjectsInRange, getOneIntersectingObject, getOneObjectAtOffset, getRotation, getWorld, getX, getY, intersects, setImage, setImage, setLocation, setRotation
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Creature

public Creature()
Method Detail

atWater

public boolean atWater()
Return true if we have just seen water in front of us.


atWorldEdge

public boolean atWorldEdge()
Test if we are close to one of the edges of the world. Return true if we are.


carryingTomato

public final boolean carryingTomato()
Check whether we are carrying a tomato.


getCurrentImage

public abstract java.lang.String getCurrentImage()
This method must be defined in subclasses. It gives subclasses the chance to specify their own images.


loadTomato

public final void loadTomato()
Load a tomato onto *another* creature. This works only if there is another creature and a tomato pile present, otherwise this method does nothing.


move

public void move()
Move forward roughly in the current direction. Sometimes we get a little off course.


randomChance

protected boolean randomChance(int percent)
Return 'true' in exactly 'percent' number of calls. That is: a call randomChance(25) has a 25% chance to return true.


removeTomato

public final boolean removeTomato()
Remove the tomato currently carried (and return true). Return false if we were not carrying one.


turn

public void turn(int angle)
Turn 'angle' degrees towards the right (clockwise).